<?php

class CodeSpace_Language_Resource_Language extends Zend_Application_Resource_ResourceAbstract
{

    public function init ()
    {
        $languageSettings = new Zend_Config_Ini(APPLICATION_PATH . '/configs/language.ini', 'settings');
        $languageSettings = $languageSettings->toArray();
        
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        
        $view = $viewRenderer->view;
        $view->addHelperPath("CodeSpace/Language/View/Helper", "CodeSpace_Language_View_Helper");
        $view->language()->setOptions($languageSettings);
        
        $front = Zend_Controller_Front::getInstance();
        
        $router = $front->getRouter();
        $oldRoutes = $router->getRoutes();
        if(count($oldRoutes)==0){
    	    $router->addDefaultRoutes();
    	}

        $routeLanguage = new Zend_Controller_Router_Route(
         	':language',
               array(
                  'language'=> $languageSettings['default']
               )
        );
        
        foreach ($router->getRoutes() as $oldRouteKey => $oldRoute)
        {
            $router->addRoute('language_' . $oldRouteKey, $routeLanguage->chain($oldRoute));
        }
        
        $router->addRoute('language', $routeLanguage);

        $front->registerPlugin(new CodeSpace_Language_Controller_Plugin_Language($languageSettings), 20);
    	
    }
    
}
?>